<?php
class S3Object {
	public $objectName = null;
	public $objectNameHash = null;
	public $versionID = null;
	public $isLatest = null;
	public $lastModified = null;
	public $etag = null;
	public $size = null;
	public $owner = null;
	public $storage = null;
	public $deleted = null;
	public $cryptID = null;
	
	public function __construct($object, $deleted = false, $cryptID = null) {
		if (!is_object($object)) { throw new Exception ("Expected an object"); }
		$this->objectName = (string) $object->Key;
		$this->objectNameHash = hash("sha256", (string) $object->Key);
		$this->versionID = (string) $object->VersionId;
		$this->lastModified = strtotime((string) $object->LastModified);
		$this->etag = str_replace('"', "", (string) $object->ETag);
		$this->size = (int) $object->Size;
		$this->owner = serialize(array("ID" => (string) $object->Owner->ID, "DisplayName" => (string) $object->Owner->DisplayName));
		$this->storage = (string) $object->StorageClass;
		$this->cryptID = null;
		
		if ($this->versionID == "null") {
			$this->versionID = null;
		}

		if ((string) $object->IsLatest == "true") {
			$this->isLatest = true;
		} else {
			$this->isLatest = false;
		}
		
		if ($deleted) {
			$this->deleted = true;
		} else {
			$this->deleted = false;
		}
		return true;
	}
	
	public function toArray() {
		return array(
			"objectName" => $this->objectName,
			"objectNameHash" => $this->objectNameHash,
			"versionID" => $this->versionID,
			"isLatest" => $this->isLatest,
			"lastModified" => $this->lastModified,
			"etag" => $this->etag,
			"size" => $this->size,
			"owner" => $this->owner,
			"storage" => $this->storage,
			"cryptID" => $this->cryptID
		);
	}
}

?>